<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="file" /> <button id="btn">提交</button>
    <script>
      btn.onclick = function (e) {
        e.preventDefault()
        // 创建formdata实例
        const formdata = new FormData()
        // 获取要上传的文件对象
        // 获取上传文件的表单项的真实dom
        const fileDom = document.querySelector('input')
        const file = fileDom.files[0]
        // 把文件对象添加到formdata中
        formdata.append('file', file)

        const xhr = new XMLHttpRequest()
        xhr.open('post', 'http://localhost:5000/test')
        xhr.send(formdata)
      }
    </script>
  </body>
</html>
